const cookie = {
  setCookie (key, value, t = 3) {
    var oDate = new Date()
    oDate.setDate(oDate.getDate() + t)
    document.cookie = key + '=' + encodeURIComponent(value) + ';expires=' + oDate.toUTCString()
  },
  getCookie (key, defaultValue = false) {
    var str = document.cookie.replace(/;\s*/g, ';')
    var cookieArr = str.split(';')
    var cookieObj = {}
    var len = cookieArr.length
    for (var i = 0; i < len; i++) {
      var item = cookieArr[i]
      var k = item.split('=')[0]
      var v = item.split('=')[1]
      cookieObj[k] = v
    }
    if (cookieObj[key]) {
      return decodeURIComponent(cookieObj[key])
    } else {
      return defaultValue
    }
  },
  removeCookie (key) {
    document.cookie = key + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT'
  }
}

export default cookie
